<template>
  <div class="content-div">
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-tabs @change="changeTab" class="tab-box" color="#1989fa" title-active-color="#1989fa" background="unset" line-width="20px" v-model="active_tab">
        <van-tab title="全部" name=""></van-tab>
        <van-tab title="申请中" name="1"></van-tab>
        <van-tab title="已通过" name="2"></van-tab>
        <van-tab title="已拒绝" name="3"></van-tab>
        <van-tab title="已取消" name="4"></van-tab>
      </van-tabs>
      <div class="list-outbox">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
          <div>
            <div class="list-item-box" v-for="(item, index) in list" :key="index">
              <div class="list-name-box">
                <span class="list-name" style="float:left;">陪诊师提交的申请</span>
                <span class="list-type" style="float:right;color:#666666;">{{item.createTime}}</span>
              </div>
              <div class="list-center-box">
                <div class="item-name flex">
                  <span>开始时间：{{item.start_time}}</span>
                </div>
                <div class="item-name flex">
                  <span>结束时间：{{item.end_time}}</span>
                </div>
                <div class="mb12 item-name flex row-between" style="margin-bottom:10px;">
                  <span>申请原因：{{item.reason}}</span>
                  <div class="btn-box" @click="cancelBreakOrder(item)">
                    <div v-if="item.state == '1'">取消</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </van-list>
      </div>
    </van-pull-refresh>
  </div>
</template>
<script>
import { Toast, Dialog } from 'vant'
import { selectAccompanyingPhysicianCeaseList, updateAccompanyingPhysicianCease } from '@/api/medicalWaiter.js'
export default {
  name: 'breakOrderList',
  data () {
    return {
      loading: false,
      finished: false,
      list: [],
      active_tab: 0,
      isLoading: false
    }
  },
  computed: {
    accompanying_physician_id () {
      return this.$store.state.user.severUserInfo.accompanying_physician_id
    }
  },
  created () {},
  methods: {
    toPage (data) {
      this.$router.push({
        path: '/order-detail-waiter',
        query: {
          order_goods_id: data.order_goods_id
        }
      })
    },
    onLoad (state) {
      selectAccompanyingPhysicianCeaseList({
        accompanying_physician_id: this.accompanying_physician_id,
        state: state
      }).then(res => {
        if (res.data.errcode === 0) {
          let array = res.data.data
          this.list = array
          this.loading = false
          this.finished = true
        }
      })
    },
    changeTab (type) {
      this.clearParam(type)
    },
    clearParam (type) {
      this.list = []
      this.loading = true
      this.finished = false
      this.onLoad(type)
    },
    onRefresh () {
      setTimeout(() => {
        Toast('刷新成功')
        this.clearParam()
        this.isLoading = false
      }, 1000)
    },
    cancelBreakOrder (item) { // 取消申请
      Dialog.confirm({
        title: '提示',
        message: '确定取消申请？'
      }).then(() => {
        updateAccompanyingPhysicianCease({ id: item.id }).then(res => {
          if (res.data.errcode === 0) {
            Toast.success('取消成功')
            this.clearParam()
            return
          }
          Toast.fail(res.data.errmsg)
        })
      })
    }
  },
  mounted () {}
}
</script>

<style scoped lang="less">
  .content-div{
    font-size: 12px;
    background-image: url('../../../../assets/images/bg.png');
    background-repeat: no-repeat;
    background-size: 100% auto;
    min-height: 100%;
    position: relative;
    .tab-box{
      width: 100%;
      height: 44px;
      position: fixed;
      top: 0;
      left: 0;
      background-image: url('../../../../assets/images/bg.png');
      background-repeat: no-repeat;
      background-size: 100% auto;
    }
    .list-outbox{
      margin: 14px auto 10px;
      width: 300px;
      padding-top: 44px;
      .list-item-box{
        margin-bottom: 10px;
        border-radius: 5px;
        border: 1px solid #eeeeee;
        box-sizing: border-box;
        padding: 8px;
        box-shadow: 0px 0px 10px #eeeeee;
        background-color: #FFFFFF;
        .list-head-box{
          height: 32px;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          align-items: center;
          padding: 0 7px;
          background-color: #f8f8f8;
          border-radius: 5px;
          margin-bottom: 8px;
          .status-box{
            display: flex;
            flex-direction: row;
            align-items: center;
            width: 100%;
            img{
              width: 24px;
              height: 24px;
              border-radius: 50%;
              margin-right: 6px;
            }
          }
        }
        .list-name-box{
          // display: flex;
          flex-direction: column;
          justify-content: space-around;
          align-items: flex-start;
          height: 17px;
          padding-bottom: 8px;
          border-bottom: 1px solid #edeae6;
          width: 100%;
          .list-name{
            font-weight: bold;
            overflow: hidden;
            text-overflow: ellipsis;
            word-break: break-all;
            white-space: nowrap;
            // width: 100%;
          }
        }
        .list-center-box{
          // padding-bottom: 10px;
          .hospital-name{
            font-weight: bold;
            padding-bottom: 4px;
          }
          .item-name{
            margin-top: 10px;
            height: 17px;
            font-size: 10px;
            .btn-box{
              display: flex;
              flex-direction: row;
              align-items: center;
              div:last-child{
                margin-left: 6px;
                color: #FFFFFF;
                height: 22px;
                background-color: #1989fa;
                padding: 0px 6px;
                line-height: 22px;
                border-radius: 4px;
                font-size: 10px;
                width: 46px;
                text-align: center;
              }
            }
          }
          .service-time{
            height: 27px;
            color: #999999;
            font-size: 10px;
            .btn-box{
              display: flex;
              flex-direction: row;
              align-items: center;
              div:last-child{
                margin-left: 6px;
                color: #FFFFFF;
                height: 22px;
                background-color: #1989fa;
                padding: 0px 6px;
                line-height: 22px;
                border-radius: 4px;
                font-size: 10px;
                width: 46px;
                text-align: center;
              }
            }
          }
        }
        .list-bottom-box{
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          align-items: center;
          padding-top: 10px;
          border-top: 1px solid #f8f8f8;
          .qiangdan-box{
            display: flex;
            flex-direction: row;
            align-items: center;
            img{
              width: 30px;
              height: 30px;
            }
            span{
              padding-left: 4px;
              color: #FF0000;
            }
          }
          .cancel-btn{
            height: 20px;
            color: #1989fa;
            border: 1px solid #1989fa;
            padding: 0px 6px;
            line-height: 20px;
            border-radius: 4px;
            font-size: 10px;
            width: 44px;
            text-align: center;
          }
        }
      }
    }
    .flex {
      display: flex;
      flex-direction: row;
      align-items: center;
    }
    .row-center {
      justify-content: center;
    }
    .row-between {
      justify-content: space-between;
    }
    .text-color {
      color: #1989fa;
    }
    .sex-img {
      width: 18px;
      height: 18px;
      margin-left: 5px;
      margin-right: 2px;
    }
    .mb12 {
      margin-bottom: 12px;
    }
  }
</style>
